package com.leetcode.partition15;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author `RKC`
 * @date 2021/10/1 10:27
 */
public class LC1436旅行终点站 {

    public static String destCity(List<List<String>> paths) {
        return hashtable(paths);
    }

    private static String hashtable(List<List<String>> paths) {
        //终点不会出现在from起点中
        Set<String> ht = new HashSet<>();
        for (List<String> path : paths) {
            ht.add(path.get(0));        //将所有起点都加入哈希表中
        }
        for (List<String> path : paths) {
            if (!ht.contains(path.get(1))) {
                return path.get(1);
            }
        }
        return null;
    }
}
